package com.imeth.cms.service.impl;

import com.imeth.base.model.Paging;
import com.imeth.cms.Fragment;
import com.imeth.cms.dao.FragmentDao;
import com.imeth.cms.service.FragmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by peter on 12/25/2015.
 */
@Service
public class FragmentServiceImpl implements FragmentService {

    @Autowired
    FragmentDao fragmentDao;

    public int save(Fragment fragment) {
        return fragmentDao.save(fragment);
    }

    public int update(Fragment fragment) {
        return fragmentDao.update(fragment);
    }

    public Fragment getById(Integer id) {
        return fragmentDao.getById(id);
    }

    public List<Fragment> query(Paging paging) {
        int records = fragmentDao.count();
        paging.setRecords(records);
        return fragmentDao.query(paging);
    }

    public int batchDelete(List<Integer> ids) {
        for (Integer id : ids) {
            fragmentDao.deleteById(id);
        }
        return ids.size();
    }
}
